package DataMock;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Iterator;

import po.StudentPO;
import po.TeacherPO;
import po.YXTeacherPO;
import appendix.ResultMessage;

import dataservice.YXTeacherDataService;

public class YXTeacherData extends UnicastRemoteObject implements YXTeacherDataService{
	private static final long serialVersionUID = 1L;
	private ArrayList<YXTeacherPO> arr;
	
	public YXTeacherData(ArrayList<YXTeacherPO> arr) throws RemoteException {
		this.arr=arr;
	}

	@Override
	public ResultMessage<?> find(long id) throws RemoteException {
		ResultMessage<YXTeacherPO> rm=null;
		Iterator it=arr.iterator();
		YXTeacherPO yxteacher=null;
		while(it.hasNext()){
			yxteacher=(YXTeacherPO)it.next();
			if(yxteacher.getID()==id){
				rm=new ResultMessage<YXTeacherPO>(yxteacher);
			}
		}
		return rm;
	}

	@Override
	public ResultMessage<?> finds() throws RemoteException {
		ResultMessage<ArrayList<YXTeacherPO>> rm=new ResultMessage<ArrayList<YXTeacherPO>>(arr);
		return rm;
	}

	@Override
	public ResultMessage<?> insert(YXTeacherPO po) throws RemoteException {
		boolean judge=true;
		if(arr.contains(po)){
			judge=false;
		}else{
			arr.add(po);
		}
		return new ResultMessage<Boolean>(judge);
	}

	@Override
	public ResultMessage<?> delete(YXTeacherPO po) throws RemoteException {
		boolean judge=true;
		if(arr.contains(po)){
			arr.remove(po);
		}else{
			judge=false;
		}
		return new ResultMessage<Boolean>(judge);
	}

	@Override
	public ResultMessage<?> update(YXTeacherPO po) throws RemoteException {
		boolean judge=true;
		if(arr.contains(po)){
			arr.remove(po);
			arr.add(po);
		}else{
			judge=false;
		}
		return new ResultMessage<Boolean>(judge);
	}

	@Override
	public void init() throws RemoteException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void finish() throws RemoteException {
		// TODO Auto-generated method stub
		
	}

}
